#!/usr/bin/env python
from blogmaker.util.paginator import JPaginator
from blogmaker.util.decorators import json_view
from blogmaker.blog.models import Entry
import logging
log = logging.getLogger(__name__)

class PostPaginator(JPaginator):
    def __init__(self, request, num_rows=25):
        query = Entry.objects.current_active()             
        super(PostPaginator, self).__init__(request, query, num_rows)
    
    def get_rows(self, object_list):
        return [{'id':entry.id, 'slug':entry.slug,
                'title':entry.headline.encode('utf-8'), 
                'pub_date':entry.pub_date.strftime('%d-%m-%Y %H:%M'),
                'closed':entry.comments_closed(),
                } for entry in object_list]

@json_view
def ajax_posts(request):
    p = PostPaginator(request)
    return p.get_response()